<?php

namespace App\Http\Controllers\admin;

use App\Dao\AreaDao;
use App\Exceptions\SysExceptions;
use App\Services\Code;

/**
 *
 */
class AreaController extends BaseController
{
    public function lists()
    {
        if(getIsHasPage()){
            return Code::message('',200,AreaDao::areas(request()->all()));
        }
        return view('admin.areas.areas');
    }


    /**
     * @throws SysExceptions
     */
    public function add()
    {
        if(isPost()){
            $params = request()->all();
            AreaDao::add($params);
            return Code::message('',200);
        }
        $areas = AreaDao::areasNoData(['level'=>1]);
        return view('admin.areas.add',[
            'areas'=>$areas
        ]);
    }

    public function edit()
    {

    }



    public function areas_childs(): array
    {
        return Code::message('',200,AreaDao::areasNoData(request()->all()));
    }

    /**
     * @return array
     * @throws SysExceptions
     */
    public function del(): array
    {
        AreaDao::delete(request('id'));
        return Code::message('删除成功',200);
    }
}
